﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebUtils;

namespace OAuth.ServiceProviders
{
    /// <summary>
    /// defines a service provider with the recommended default settings
    /// </summary>
    public abstract class DefaultOAuthServiceProvider : IServiceProvider
    {
        protected static readonly UnEncodedURLParameter[] defaultEmptyParams = new UnEncodedURLParameter[] { };
        protected static readonly Parameter[] defaultParams = new Parameter[] { };

        readonly IWebRequest request;
        readonly IWebRequest access;

        public DefaultOAuthServiceProvider(
            string pRequestUrl,
            string pAccessUrl)
        {
            request = new DefaultWebRequest(
                WebMethodVerbEnum.POST,
                pRequestUrl,
                defaultEmptyParams,
                defaultEmptyParams,
                defaultParams);

            access = new DefaultWebRequest(
                WebMethodVerbEnum.POST,
                pRequestUrl,
                defaultEmptyParams,
                defaultEmptyParams,
                defaultParams);
        }

        public DefaultOAuthServiceProvider(IWebRequest pRequest, IWebRequest pAccess)
        {
            request = pRequest;
            access = pAccess;
        }

        public virtual IWebRequest RequestTokenRequest { get { return request; } }
        public virtual SignatureMethod RequestTokenSignatureMethod { get { return SignatureMethods.Hmacsha1.Instance; } }
        public virtual AuthInfoLocation RequestAuthInfoLocation { get { return AuthLocations.AuthHeader.Instance; } }
        public abstract void WithRequestTokenResult( string pRequestToken, string pRequestTokenSecret, IEnumerable<UnEncodedURLParameter> pAdditionalParameters );

        public virtual IWebRequest AccessTokenRequest { get { return access; } }
        public virtual SignatureMethod AccessTokenSignatureMethod { get { return SignatureMethods.Hmacsha1.Instance; } }
        public virtual AuthInfoLocation AccessAuthInfoLocation { get { return AuthLocations.AuthHeader.Instance; } }
        public virtual void WithAccessTokenResult( string pAccessToken, string pAccessTokenSecret, IEnumerable<UnEncodedURLParameter> pAdditionalParameters ) { }

        public virtual SignatureMethod ProtectedResourceSignatureMethod { get { return SignatureMethods.Hmacsha1.Instance; } }
        public virtual AuthInfoLocation ProtectedResourceAuthInfoLocation { get { return AuthLocations.AuthHeader.Instance; } }
    }
}
